// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

/** 获取当前的用户 GET /mock/currentUser */
export async function currentUser( options?: { [key: string]: any } ) {
  return request<{
    data: API.CurrentUser;
  }>('/users/currentUser', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 退出登录接口 POST /mock/login/outLogin */
export async function outLogin( options?: { [key: string]: any } ) {
  return request<Record<string, any>>('/users/logout', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 登录接口 POST /mock/login/account */
export async function login( body: API.LoginParams, options?: { [key: string]: any } ) {
  return request<API.LoginResult>('/users/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 此处后端没有提供注释 GET /mock/notices */
export async function getNotices( options?: { [key: string]: any } ) {
  return request<API.NoticeIconList>('/mock/notices', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取规则列表 GET /mock/rule */
export async function rule(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
    sortField?: string;
    sortOrder?: string;
  },
  options?: { [key: string]: any },
) {
  if (options) {
    let keys = Object.keys(options);
    params.sortField = keys[0];
    params.sortOrder = options[keys[0]];

  }
  return request<API.RuleList>('/businessOrder', {
    method: 'GET',
    params: {
      ...params,
    },
  });
}

/** 更新规则 PUT /mock/rule */
export async function updateRule( options?: { [key: string]: any } ) {
  return request<API.RuleListItem>('/mock/rule', {
    method: 'POST',
    data: {
      method: 'update',
      ...(options || {}),
    },
  });
}

/** 新建规则 POST /mock/rule */
export async function addRule( options?: { [key: string]: any } ) {
  return request<API.RuleListItem>('/businessOrder', {
    method: 'POST',
    data: {
      ...options?.data,
    },
  });
}

/** 删除规则 DELETE /mock/rule */
export async function removeRule( ids: number ) {
  return request<Record<string, any>>('/businessOrder/' + ids, {
    method: 'DELETE',
  });
}
